﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using NLBS.Entity;
using NLBS.Data;
using NLBS.Text;
using System.Text;
using NLBS.Data.Business;
using NLBS.Views;
using NLBS.Web;

namespace NLBS.Control
{
    public partial class content : BaseUserControl, IContentView
    {
        #region Presenter

        private ContentPresenter _presenter;

        public ContentPresenter Presenter
        {
            get
            {
                if (this._presenter == null)
                    _presenter = new ContentPresenter();
                this._presenter.View = this;
                return _presenter;
            }
        }

        private void PresenterInit()
        {
            if (!this.IsPostBack)
            {
                this.Presenter.OnViewInitialized();
            }

            this.Presenter.OnViewLoaded();
        }
        #endregion

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            BindArticleData();
        }

        public void BindArticleData()
        {
          
            startIndex = AspNetPager1.StartRecordIndex;
            if (Request.Cookies[StateKey.ArticleModeCookieKey].Value == "normal")
            {
                AspNetPager1.PageSize = BlogInfo.ArticlePerPageNormal;
            }
            else
            {
                AspNetPager1.PageSize = BlogInfo.ArticlePerPageList;

            }
            this.pageSize = AspNetPager1.PageSize;          
            PresenterInit();
            if (Request.Cookies["articleMode"].Value == "normal")
            {
                normalArticleList.DataSource = this.artList;
                normalArticleList.DataBind();
            }
            else
            {
                listArticle.DataSource = artList;
                listArticle.DataBind();
            }
        }

        #region IContentView Members

      
        public int cat
        {
            get
            {
                return RequestWrapper.GetQueryInt("catID");
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public int user
        {
            get
            {
                return RequestWrapper.GetQueryInt("user");
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string date
        {
            get
            {
                return RequestWrapper.GetQueryString("date");
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string selected
        {
            get
            {
                return RequestWrapper.GetQueryString("selected");
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        private int _startIndex;
        public int startIndex
        {
            get
            {
                return _startIndex;
            }
            set
            {       
                _startIndex=value;
            }
        }
        private int _pageSize;
        public int pageSize
        {
            get
            {
                return _pageSize;
            }
            set
            {

                _pageSize=value;
            }
        }
        private string _pageUrl;
        public string pageUrl
        {
            get
            {
                return _pageUrl;
            }
            set
            {
                _pageUrl=value;
            }
        }
        private IPagedCollection<Article> _artList;
        public IPagedCollection<Article> artList
        {
            get
            {
                return _artList;
            }
            set
            { 
                _artList = value;
                AspNetPager1.RecordCount = artList.MaxItems;
                AspNetPager1.EnableUrlRewriting = true;
                AspNetPager1.UrlRewritePattern = pageUrl;
            }
        }

        public string q
        {
            get { return RequestWrapper.GetQueryString("q"); }
        }

        public string tag
        {
            get { return RequestWrapper.GetQueryString("tag"); }
        }

        #endregion
    }
}